//
//  SecondDetailCon.m
//  ShopDemo
//
//  Created by 飞扬的青春 on 2018/7/31.
//  Copyright © 2018年 飞扬的青春. All rights reserved.
//

#import "SecondDetailCon.h"
#import "PingLunwCell.h"
#import "MorePingLunController.h"
#import "PingLunDetailCon.h"

#import "WXApi.h"
#import "AppDelegate.h"
#import <WebKit/WebKit.h>
//微信开发者ID
#define URL_APPID @"wx5160f8411c9f33ea"
#define URL_SECRET @"ea8489b1810a14ff9c30292e6cb360f6"



@interface SecondDetailCon ()<UITableViewDelegate,UITableViewDataSource,WKNavigationDelegate,WXDelegate>

{
    AppDelegate *appdelegate;
    
}

@property (strong, nonatomic) WKWebView *webview;
@property (weak, nonatomic) IBOutlet UITableView *listTableview;
@property(nonatomic,strong)UIView *headerView;
@property(nonatomic,assign)CGFloat webHeight;
@property(nonatomic,strong)NSArray *contentArray;
@property(nonatomic,strong)UITextField *plfield;
@property(nonatomic,strong)UIView *backview;

@end

@implementation SecondDetailCon

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatBackViewMethod];
    self.webview = [[WKWebView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 1)];
//    self.webview.delegate = self;
    self.webview.navigationDelegate = self;
     _webview.scrollView.scrollEnabled = NO;
    [self loadWebViewString:self.detailDic[@"CONTENT"]];
    [self createTableviewMethod];
    [self creatHeaderViewMethod];
    [self bottomViewMethod];
    NSString *strurl = [NSString stringWithFormat:@"/dashop/newsrate/app/list.do?NEWS_ID=%@&CurrentPage=1&NEWSRATE_PARENTID=0",self.detailDic[@"NEWS_ID"]];
    [self contentDataMethodWithUrl:[MethodClass returnUrlSetStrWSDLURL:strurl]];
    
    
    UIBarButtonItem *btn = [[UIBarButtonItem  alloc]initWithTitle:@"分享" style:UIBarButtonItemStylePlain target:self action:@selector(ShareButtonAction:)];
    UIBarButtonItem *btn1 = [[UIBarButtonItem  alloc]initWithTitle:@"举报" style:UIBarButtonItemStylePlain target:self action:@selector(JuBaoButtonAction:)];
    self.navigationItem.rightBarButtonItems = @[btn,btn1];
    
}

-(void)ShareButtonAction:(UIBarButtonItem *)item{
    
    [self isShareToPengyouquan:NO];
}
-(void)JuBaoButtonAction:(UIBarButtonItem *)item{
    self.backview.hidden = NO;
    //返回封装好的编辑框
    UIView *bigview = [self returnBigTextviewMetodUserDic:nil];
    [self.backview addSubview:bigview];
    bigview.sd_layout
    .topSpaceToView(self.backview, 100)
    .leftSpaceToView(self.backview, 30)
    .rightSpaceToView(self.backview,30)
    .heightIs(kScreenHeight/3);
}


//添加主背景页面和设置背景页面
-(void)creatBackViewMethod{
    //添加主背景view
    self.backview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    self.backview.backgroundColor = [[UIColor darkGrayColor] colorWithAlphaComponent:0.5];
    [self.navigationController.view addSubview:self.backview];
    self.backview.userInteractionEnabled = YES;
    self.backview.hidden = YES;
    
}


//返回大的编辑框
-(UIView *)returnBigTextviewMetodUserDic:(NSDictionary *)dic{
    UIView *bigview = [UIView new];
    bigview.layer.masksToBounds = YES;
    bigview.layer.cornerRadius = 5;
    bigview.backgroundColor = LineBackColor;
    UILabel *titLab = [UILabel new];
    titLab.font = [UIFont systemFontOfSize:15];
    titLab.textColor = [UIColor blackColor];
    titLab.textAlignment = NSTextAlignmentCenter;
    titLab.text = @"举报内容";
    [bigview addSubview:titLab];
    titLab.sd_layout
    .topSpaceToView(bigview, 0)
    .leftSpaceToView(bigview, 0)
    .rightSpaceToView(bigview, 0)
    .heightIs(30);
    UITextView *textview = [UITextView new];
    textview.tag = 603;
    textview.layer.masksToBounds = YES;
    textview.layer.cornerRadius = 5;
    textview.backgroundColor = [UIColor whiteColor];
    [bigview addSubview:textview];
    textview.sd_layout
    .topSpaceToView(titLab, 5)
    .leftSpaceToView(bigview, 10)
    .rightSpaceToView(bigview, 10)
    .bottomSpaceToView(bigview, 50);
    NSInteger btnWidth = (kScreenWidth-60-40)/2;
    MineButton *cancelBtn = [MineButton buttonWithType:UIButtonTypeSystem];
    cancelBtn.tag = 600;
    cancelBtn.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.3];
    [cancelBtn addTarget:self action:@selector(TextButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancelBtn setTitleColor:LineBackColor forState:UIControlStateNormal];
    [bigview addSubview:cancelBtn];
    cancelBtn.sd_layout
    .topSpaceToView(textview, 10)
    .leftSpaceToView(bigview, 10)
    .bottomSpaceToView(bigview, 10)
    .widthIs(btnWidth);
    MyButton *okBtn = [MyButton buttonWithType:UIButtonTypeSystem];
    [okBtn addTarget:self action:@selector(TextButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    okBtn.tag = 601;
    okBtn.backgroundColor = BackColor;
    [okBtn setTitle:@"确认" forState:UIControlStateNormal];
    [okBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [bigview addSubview:okBtn];
    okBtn.sd_layout
    .topSpaceToView(textview, 10)
    .rightSpaceToView(bigview, 10)
    .bottomEqualToView(cancelBtn)
    .widthIs(btnWidth);
    return bigview;
}

-(void)TextButtonAction:(MineButton *)sender{
    UITextView *textview = [self.backview viewWithTag:603];
    if (sender.tag == 601) {
        if (textview.text.length > 0) {
            NSString *urlstr = [NSString stringWithFormat:@"/dashop/news/app/tipOffs.do?NEWS_ID=%@&NEWS_TIPOFFS=%@",self.detailDic[@"NEWS_ID"],textview.text];
            NSString *endstr = [MethodClass returnUrlSetStrWSDLURL:urlstr];
            NSString  *newUrlString = [endstr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
            [self JuBaoRequestMethodWithUrl:newUrlString];
        }else{
            [self alerWithMessage:@"请填写举报内容"];
        }
    }else{
        self.backview.hidden = YES;
        [self.backview.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    }
}
//举报
-(void)JuBaoRequestMethodWithUrl:(NSString *)url{
    [YQNetworking getWithUrl:url refreshRequest:YES cache:NO params:nil progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
    } successBlock:^(id response) {
        NSDictionary *dic = response;
        if ([dic[@"RESULT"] integerValue] == 1) {
            [[NSOperationQueue mainQueue]addOperationWithBlock:^{
                [self alerWithMessage:dic[@"MESSAGE"]];
                self.backview.hidden = YES;
                [self.backview.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
            }];
        }
    } failBlock:^(NSError *error) {
        
    }];
    
}

-(void)isShareToPengyouquan:(BOOL)isPengyouquan{
    /** 标题
     * @note 长度不能超过512字节
     */
    // @property (nonatomic, retain) NSString *title;
    /** 描述内容
     * @note 长度不能超过1K
     */
    //@property (nonatomic, retain) NSString *description;
    /** 缩略图数据
     * @note 大小不能超过32K
     */
    //  @property (nonatomic, retain) NSData   *thumbData;
    /**
     * @note 长度不能超过64字节
     */
    // @property (nonatomic, retain) NSString *mediaTagName;
    /**
     * 多媒体数据对象，可以为WXImageObject，WXMusicObject，WXVideoObject，WXWebpageObject等。
     */
    // @property (nonatomic, retain) id        mediaObject;
    
    /*! @brief 设置消息缩略图的方法
     *
     * @param image 缩略图
     * @note 大小不能超过32K
     */
    //- (void) setThumbImage:(UIImage *)image;
    //缩略图
    UIImage *image = [UIImage imageNamed:@"zhImage.png"];
    WXMediaMessage *message = [WXMediaMessage message];
    message.title = self.detailDic[@"TITLE"];
    message.description = [NSString stringWithFormat:@"%@",self.detailDic[@"SHORTCONTENT"]];
    //png图片压缩成data的方法，如果是jpg就要用 UIImageJPEGRepresentation
    message.thumbData = UIImagePNGRepresentation(image);
    [message setThumbImage:image];
    
    
    WXWebpageObject *ext = [WXWebpageObject object];
    NSString *urlstr = [NSString stringWithFormat:@"/dashop/webnewsdetail.html?NEWID=%@",self.detailDic[@"NEWS_ID"]];
    NSString *endstr = [MethodClass returnUrlSetStrWSDLURL:urlstr];
    ext.webpageUrl = endstr;
    message.mediaObject = ext;
    message.mediaTagName = @"ISOFTEN_TAG_JUMP_SHOWRANK";
    
    SendMessageToWXReq *sentMsg = [[SendMessageToWXReq alloc]init];
    sentMsg.message = message;
    sentMsg.bText = NO;
    //选择发送到会话(WXSceneSession)或者朋友圈(WXSceneTimeline)
    if (isPengyouquan) {
        sentMsg.scene = WXSceneTimeline;  //分享到朋友圈
    }else{
        sentMsg.scene =  WXSceneSession;  //分享到会话。
    }
    
    //如果我们想要监听是否成功分享，我们就要去appdelegate里面 找到他的回调方法
    // -(void) onResp:(BaseResp*)resp .我们可以自定义一个代理方法，然后把分享的结果返回回来。
    appdelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    //添加对appdelgate的微信分享的代理
    appdelegate.wxDelegate = self;
    [WXApi sendReq:sentMsg completion:nil];
    
}

#pragma mark 监听微信分享是否成功 delegate
-(void)shareSuccessByCode:(int)code{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"分享成功" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alert show];
}

-(void)loginSuccessByCode:(NSString *)code{
    
}


//评论列表
-(void)contentDataMethodWithUrl:(NSString *)url{
    [YQNetworking getWithUrl:url refreshRequest:YES cache:NO params:nil progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
    } successBlock:^(id response) {
        self.contentArray = response;
        [[NSOperationQueue mainQueue]addOperationWithBlock:^{
            [self.listTableview reloadData];
        }];
    } failBlock:^(NSError *error) {
        
    }];
    
}

-(void)createTableviewMethod{
    
    self.listTableview.dataSource = self;
    self.listTableview.delegate = self;
    [self.listTableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"onecell"];
    [self.listTableview registerClass:[PingLunwCell class] forCellReuseIdentifier:@"twocell"];
    //分隔线
    self.listTableview.separatorStyle = UITableViewCellAccessoryNone;
    //去掉尾部多余的空白
    [self.listTableview setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];
    
    UIView *backview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 50*kJLXWidthScale)];
    UILabel *lab = [UILabel new];
    lab.text = @"查看更多＞＞";
    lab.font = [UIFont systemFontOfSize:20*kJLXWidthScale weight:0.2];
    lab.textColor = [UIColor orangeColor];
    lab.textAlignment = NSTextAlignmentCenter;
    
    MyGestureTap *tap = [[MyGestureTap alloc]initWithTarget:self action:@selector(morePilngLunTap:)];
    lab.userInteractionEnabled = YES;
    [lab addGestureRecognizer:tap];
    [backview addSubview:lab];
    lab.sd_layout
    .centerXEqualToView(backview)
    .centerYEqualToView(backview)
    .widthIs(kScreenWidth)
    .heightIs(50*kJLXWidthScale);
    self.listTableview.tableFooterView = backview;
}
-(void)morePilngLunTap:(MyGestureTap *)tap{
    MorePingLunController *morevc = [[MorePingLunController alloc]init];
    morevc.navigationItem.title = @"社区评论";
    morevc.condic = self.detailDic;
    NSString *strurl = [NSString stringWithFormat:@"/dashop/newsrate/app/list.do?NEWS_ID=%@&CurrentPage=1&NEWSRATE_PARENTID=0",self.detailDic[@"NEWS_ID"]];
    morevc.urlstr = strurl;
    [self.navigationController pushViewController:morevc animated:YES];
}
-(void)creatHeaderViewMethod{
       CGRect rect = [self.detailDic[@"SHORTCONTENT"] boundingRectWithSize:CGSizeMake(kScreenWidth, MAXFLOAT) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15*kJLXWidthScale]} context:nil];
    self.headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, rect.size.height + 30)];
    UILabel *titlab = [UILabel new];
    titlab.textColor = [UIColor darkGrayColor];
    titlab.text = [NSString stringWithFormat:@"摘要：%@",self.detailDic[@"SHORTCONTENT"]];
    titlab.numberOfLines = 0;
    titlab.font = [UIFont systemFontOfSize:15*kJLXWidthScale];
    [self.headerView addSubview:titlab];
    titlab.sd_layout
    .topSpaceToView(self.headerView, 20*kJLXWidthScale)
    .leftSpaceToView(self.headerView, 10*kJLXWidthScale)
    .rightSpaceToView(self.headerView, 10*kJLXWidthScale)
    .autoHeightRatio(0);
    self.listTableview.tableHeaderView = self.headerView;
    
}


-(void)loadWebViewString:(NSString *)loadString
{
    NSString *content = [[NSString alloc] init];
    if (loadString == nil || loadString == NULL) {
        content =@"";
    }else
        content = [NSString stringWithFormat:@"<html> \n"
                  "<head> \n"
                  "<style type=\"text/css\"> \n"
                  "body {font-size:15px;}\n"
                  "</style> \n"
                  "</head> \n"
                  "<body>"
                  "<script type='text/javascript'>"
                  "window.onload = function(){\n"
                  "var $img = document.getElementsByTagName('img');\n"
                  "for(var p in  $img){\n"
                  " $img[p].style.width = '100%%';\n"
                  "$img[p].style.height ='auto'\n"
                  "}\n"
                  "}"
                  "</script>%@"
                  "</body>"
                  "</html>",loadString];
    [_webview loadHTMLString:content baseURL:nil];
}

-(void)bottomViewMethod{
    UIView *bottomview = [UIView new];
    bottomview.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bottomview];
    bottomview.sd_layout
    .bottomSpaceToView(self.view,0)
    .centerXEqualToView(self.view)
    .widthIs(kScreenWidth)
    .heightIs(60*kJLXWidthScale);
    if (kScreenHeight == 812) {
        bottomview.sd_layout
        .bottomSpaceToView(self.view,34)
        .centerXEqualToView(self.view)
        .widthIs(kScreenWidth)
        .heightIs(60*kJLXWidthScale);
    }
    
    UITextField *field = [UITextField new];
    self.plfield = field;
    field.layer.masksToBounds = YES;
    field.layer.cornerRadius = 5*kJLXWidthScale;
    field.layer.borderColor = [UIColor orangeColor].CGColor;
    field.layer.borderWidth = 1;
    field.placeholder = @"  说点什么……";
    field.font = [UIFont systemFontOfSize:18*kJLXWidthScale];
    [bottomview addSubview:field];
    field.sd_layout
    .leftSpaceToView(bottomview, 8*kJLXWidthScale)
    .bottomSpaceToView(bottomview, 10*kJLXWidthScale)
    .heightIs(45*kJLXWidthScale)
    .rightSpaceToView(bottomview, 80*kJLXWidthScale);
    
    UILabel *lab = [UILabel new];
    lab.textAlignment = NSTextAlignmentCenter;
    lab.textColor = [UIColor orangeColor];
    lab.text = @"评论";
    lab.font = [UIFont systemFontOfSize:20*kJLXWidthScale];
    [bottomview addSubview:lab];
    lab.sd_layout
    .bottomSpaceToView(bottomview, 10*kJLXWidthScale)
    .rightSpaceToView(bottomview, 10*kJLXWidthScale)
    .leftSpaceToView(field, 10*kJLXWidthScale)
    .heightIs(45*kJLXWidthScale);
    self.listTableview.sd_layout
    .bottomSpaceToView(bottomview, 0);
    MyGestureTap *tap = [[MyGestureTap alloc]initWithTarget:self action:@selector(pinglunTap:)];
    lab.userInteractionEnabled = YES;
    [lab addGestureRecognizer:tap];
    
}

-(void)pinglunTap:(MyGestureTap*)tap{
    
    NSString *strurl = [NSString stringWithFormat:@"/dashop/newsrate/app/add.do?NEWSRATE_USERID=%@&NEWSRATE_USERNAME=%@&NEWSRATE_CONTENT=%@&NEWS_ID=%@&NEWSRATE_PARENTID=0",[UserDefault objectForKey:LogUserID],[UserDefault objectForKey:LogUserName],self.plfield.text,self.detailDic[@"NEWS_ID"]];
    NSString *endurl = [MethodClass returnUrlSetStrWSDLURL:strurl];
   NSString  *newUrlString = [endurl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    [self addPingLunMethodWithUrl:newUrlString];
    
}

//添加评论
-(void)addPingLunMethodWithUrl:(NSString *)url{
    [YQNetworking getWithUrl:url refreshRequest:YES cache:NO params:nil progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
    } successBlock:^(id response) {
        if ([response[@"RESULT"]integerValue] == 1) {
             NSString *strurl = [NSString stringWithFormat:@"/dashop/newsrate/app/list.do?NEWS_ID=%@&CurrentPage=1&NEWSRATE_PARENTID=0",self.detailDic[@"NEWS_ID"]];
            [self contentDataMethodWithUrl:[MethodClass returnUrlSetStrWSDLURL:strurl]];
        }
    } failBlock:^(NSError *error) {
        
    }];
    
}

#pragma mark --UITableViewDelegate,UITableViewDataSource--
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }else{
       return self.contentArray.count;
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"onecell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell.contentView addSubview:self.webview];
        return cell;
    }else{
        PingLunwCell *cell = [tableView dequeueReusableCellWithIdentifier:@"twocell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        NSDictionary *dic = self.contentArray[indexPath.row];
        cell.titlab.text = [NSString stringWithFormat:@"%@",dic[@"NEWSRATE_USERIDNAME"]];
        cell.datelab.text = [NSString stringWithFormat:@"%@",dic[@"NEWSRATE_ADDTIME"]];
        cell.contentlab.text = [NSString stringWithFormat:@"%@",dic[@"NEWSRATE_CONTENT"]];
        cell.titimagevi.layer.masksToBounds = YES;
        cell.titimagevi.layer.cornerRadius = cell.titimagevi.width/2;
        NSString *strurl = [NSString stringWithFormat:@"/dashop/%@",dic[@"SFID"]];
        NSString *urlstr = [MethodClass returnUrlSetStrWSDLURL:strurl];
        [cell.titimagevi sd_setImageWithURL:[NSURL URLWithString:urlstr]];
        return cell;
    }
    
    
    
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return self.webHeight + 50*kJLXWidthScale;
    }else{
        return 100*kJLXWidthScale;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 1) {
        return 50*kJLXWidthScale;
    }else{
        return 0;
    }
    
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *backview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 50*kJLXWidthScale)];
    UILabel *lab = [UILabel new];
    lab.text = @"--精彩评论--";
    lab.font = [UIFont systemFontOfSize:20*kJLXWidthScale weight:0.2];
    lab.textColor = [UIColor orangeColor];
    lab.textAlignment = NSTextAlignmentCenter;
    [backview addSubview:lab];
    lab.sd_layout
    .centerXEqualToView(backview)
    .centerYEqualToView(backview)
    .widthIs(kScreenWidth)
    .heightIs(50*kJLXWidthScale);
    return backview;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dic = self.contentArray[indexPath.row];
    PingLunDetailCon *plVC = [[PingLunDetailCon alloc]init];
    plVC.maindic = dic;
    [self.navigationController pushViewController:plVC animated:YES];
    
}

#pragma =======webviewDeleget==========


- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
    NSLog(@"加载完成");
    
    [webView evaluateJavaScript:@"document.body.scrollWidth"completionHandler:^(id _Nullable result,NSError * _Nullable error){

        double width = [result floatValue];
        [webView evaluateJavaScript:@"document.body.scrollHeight"completionHandler:^(id _Nullable result,NSError * _Nullable error){

            double height = [result floatValue] / width * kScreenWidth;
            NSLog(@"scrollHeight高度：%.2f",height);
            self.webview.frame = CGRectMake(self.webview.frame.origin.x,self.webview.frame.origin.y, kScreenWidth, height + 30*kJLXWidthScale);
            self.webHeight = height;
            [self.listTableview reloadData];
       
        }];

//        self.webview.frame = CGRectMake(self.webview.frame.origin.x,self.webview.frame.origin.y, kScreenWidth, [result floatValue] + 30*kJLXWidthScale);
//        self.webHeight = [result floatValue];
//        [self.listTableview reloadData];
   
    }];
    

//    [webView evaluateJavaScript:@"document.body.offsetHeight"completionHandler:^(id _Nullable result,NSError * _Nullable error){
//
//        NSLog(@"offsetHeight高度：%.2f",[result floatValue]);
//        self.webview.frame = CGRectMake(self.webview.frame.origin.x,self.webview.frame.origin.y, kScreenWidth, [result floatValue] + 30*kJLXWidthScale);
//        self.webHeight = [result floatValue];
//        [self.listTableview reloadData];
//    }];
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    CGFloat sectionHeaderHeight = 50;
    if (scrollView.contentOffset.y <= sectionHeaderHeight && scrollView.contentOffset.y> 0) {
        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
    }else
        if(scrollView.contentOffset.y >= sectionHeaderHeight){
            
            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
        }
}

//封装提示框方法
-(void)alerWithMessage:(NSString *)msg{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
    [self presentViewController:alert animated:YES completion:^{
        //延迟1秒自动消失
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [alert dismissViewControllerAnimated:YES completion:nil];
        });
    }];
}

@end

